//
//  DataShoppingCell.m
//  NineGroupProject
//
//  Created by dllo on 15/12/23.
//  Copyright © 2015年 蓝鸥科技. All rights reserved.
//

#import "DataShoppingCell.h"
#import "UIImageView+WebCache.h"
#import "Masonry.h"

@implementation DataShoppingCell


-(instancetype)initWithFrame:(CGRect)frame{
    
    self = [super initWithFrame:frame];
    if (self) {
        
        [self creacteSubCell];
    }
    return self;
}

-(void)creacteSubCell{
    
    self.headImage = [[UIImageView alloc]init];
    [self.contentView addSubview:self.headImage];
    self.headImage.backgroundColor = [UIColor blueColor];
    [self.headImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.and.top.mas_equalTo(0);
        make.size.mas_equalTo(170 * WID);
    }];
    
    UILabel *lable = [[UILabel alloc]init];
    lable.font = [UIFont systemFontOfSize:13];
    [lable setTextColor:[UIColor whiteColor]];
    lable.backgroundColor = [UIColor colorWithRed:0.5 green:0.5 blue:0.5 alpha:0.3];
    lable.text = @"￥";
    [self.contentView addSubview:lable];
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(0);
        make.top.mas_equalTo(155 * WID);
        make.width.mas_equalTo(80 * WID);
        make.height.mas_equalTo(15 * HEI);
    }];
    
    self.priceLabel = [[UILabel alloc]init];
    self.priceLabel.font = [UIFont systemFontOfSize:13];
    [self.priceLabel setTextColor:[UIColor whiteColor]];
    [self.contentView addSubview:self.priceLabel];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(lable.mas_left).offset(15 * WID);
        make.top.equalTo(lable.mas_top).offset(2.5 * HEI);
        make.width.mas_equalTo(100 * WID);
        make.height.mas_equalTo(10 * HEI);
    }];
    
    self.nameLabel = [[UILabel alloc]init];
    self.nameLabel.font = [UIFont systemFontOfSize:14];
    self.nameLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.nameLabel];
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImage.mas_left);
        make.top.equalTo(self.headImage.mas_bottom).offset(2.5 * HEI);
        make.width.equalTo(self.headImage.mas_width);
        make.height.mas_equalTo(15 * HEI);
    }];
    
    self.presentLabel = [[UILabel alloc]init];
    self.presentLabel.font = [UIFont systemFontOfSize:14];
    self.presentLabel.textAlignment = NSTextAlignmentCenter;
    [self.contentView addSubview:self.presentLabel];
    [self.presentLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.headImage.mas_left);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(2.5 * HEI);
        make.width.equalTo(self.headImage.mas_width);
        make.height.equalTo(self.nameLabel.mas_height);
    }];
    
    self.fansImage = [[UIImageView alloc]init];
    self.fansImage.image = [UIImage imageNamed:@"iconfont-heart.png"];
    [self.contentView addSubview:self.fansImage];
    [self.fansImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(65 * WID);
        make.top.equalTo(self.presentLabel.mas_bottom).offset(2.5 * HEI);
        make.size.mas_equalTo(16 * WID);
    }];
    
    self.favNum = [[UILabel alloc]init];
    self.favNum.font = [UIFont systemFontOfSize:13];
    [self.contentView addSubview:self.favNum];
    [self.favNum mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.fansImage.mas_right).offset(5 * WID);
        make.top.equalTo(self.fansImage.mas_top);
        make.width.equalTo(self.fansImage.mas_width).multipliedBy(4);
        make.height.equalTo(self.fansImage.mas_height);
    }];
    
}

-(void)setModel:(ShoppingModel *)model{
    
    _model = model;
    NSURL *url = [NSURL URLWithString:self.model.image];
    [self.headImage sd_setImageWithURL:url placeholderImage:[UIImage imageNamed:@"placeholderImag.png"]];
    NSString *string = [NSString stringWithFormat:@"%.1f", self.model.price];
    self.priceLabel.text = string;
    NSString *str = [NSString stringWithFormat:@"%ld", self.model.favNum];
    self.favNum.text = str;
    self.nameLabel.text = self.model.nickName;
    self.presentLabel.text = self.model.productDescription;
}


@end
